package com.qyhl.webtv.module_circle.circle.add;


import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.circle.CircleHomeBean;
import com.qyhl.webtv.commonlib.entity.UpTokenBean;
import com.qyhl.webtv.commonlib.entity.act.UploadBean;
import com.qyhl.webtv.commonlib.entity.intergral.CoinBean;

import java.util.HashMap;
import java.util.List;

/**
 * Created by helin on 2018/1/24.
 */

public class AddCirclePresenter implements AddCircleContract.AddCirclePresenter {

    private final AddCircleContract.AddCircleView view;
    private final AddCircleModel model;

    AddCirclePresenter(AddCircleContract.AddCircleView view) {
        this.view = view;
        this.model = new AddCircleModel(this);
    }

    @Override
    public void getTagError() {
        view.getTagError();
    }

    @Override
    public void getTagSuccess(List<CircleHomeBean.TagList> data) {
        view.getTagSuccess(data);
    }

    @Override
    public void postError(String msg) {
        view.postError(msg);
    }

    @Override
    public void postSuccess(int topicId) {
        view.postSuccess(topicId);
    }

    @Override
    public void getTagList() {
        model.getTagList();
    }

    @Override
    public void postData(HashMap<String, String> data) {
        model.postData(data);
    }

    @Override
    public void getTokenError() {
        view.getTokenError();
    }

    @Override
    public void getTokenSuccess(UpTokenBean data, boolean isUp) {
        view.getTokenSuccess(data, isUp);
    }

    @Override
    public void combinationData(String content, String tagIds, String postion, int type, List<UploadBean> files) {

        //封装图片地址数据
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < files.size(); i++) {
            for (int j = 0; j < files.size(); j++) {
                UploadBean uploadBean = files.get(j);
                if (uploadBean.getIndex() == i) {
                    String path = uploadBean.getUrl();
                    stringBuffer.append(path + ",");
                }
            }
        }
        String userName = CommonUtils.getInstance().getUserName();
        HashMap<String, String> data = new HashMap<>();
        data.put("method", "createTopic");
        data.put("siteId", CommonUtils.getInstance().getSite() + "");
        data.put("username", userName);
        data.put("content", content);
        data.put("position", postion);
        data.put("type", type + "");
        data.put("tags", tagIds);
        data.put("urls", stringBuffer.toString());
        model.postData(data);

    }


    @Override
    public void combinationVideoData(String content, String s, String postionStr, int type, List<UploadBean> files) {
        HashMap<String, String> data = new HashMap<>();
        for (int i = 0; i < files.size(); i++) {
            UploadBean uploadBean = files.get(i);
            String path = uploadBean.getUrl();
            if (uploadBean.getType() == 3) {
                data.put("urls", path);
            } else if (uploadBean.getType() == 4) {
                data.put("videoThumb", path);
            }
        }
        data.put("method", "createTopic");
        data.put("siteId", CommonUtils.getInstance().getSite() + "");
        String userName = CommonUtils.getInstance().getUserName();
        data.put("username", userName);
        data.put("content", content);
        data.put("position", postionStr);
        data.put("type", type + "");
        data.put("tags", s);
        model.postData(data);

    }

    @Override
    public void getCheckType(boolean isUp) {
        model.getCheckType(isUp);
    }

    @Override
    public void setCheckType(int typeId, boolean isUp) {
        view.setCheckType(typeId, isUp);
    }

    @Override
    public void getCoin(String username) {
        model.getCoin(username);
    }

    @Override
    public void getCoinSuccess(CoinBean bean) {
        view.getCoinSuccess(bean);
    }

    @Override
    public void getCoinFailure(String msg) {
        view.getCoinFailure(msg);
    }

    @Override
    public void getToken() {
        model.getUpToken(false);
    }

    @Override
    public void postData(String content, StringBuffer tagIds, String postionStr, int i) {
        HashMap<String, String> data = new HashMap<>();
        data.put("method", "createTopic");
        data.put("siteId", CommonUtils.getInstance().getSite() + "");
        String userName = CommonUtils.getInstance().getUserName();
        data.put("username", userName);
        data.put("content", content);
        data.put("position", postionStr);
        data.put("type", i + "");
        data.put("tags", tagIds.toString());
        model.postData(data);
    }


}
